/**
 * Created by DELL on 2017/6/6.
 */
import React  from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TextInput,
    Image,
    PixelRatio,
    TouchableHighlight,
    TouchableOpacity,

} from 'react-native';

import BaseComponent, {base} from '../../base/Base' ;

let {USER_INFO}=base.fields;

export default class Setting extends BaseComponent {
    // static navigationOptions = {
    //     //title:'设置',//navigation 的默认设置属性 标题
    // }

    constructor(props) {
        super(props);

    }

    componentWillMount() {

    }

    _pressItem=(index)=>{
       switch (index){
           case 0:
               this.props.navigation.navigate('SwiperPage')
               break
           case 1:
               break
           case 2:
               break
           case 3:
               break
       }
    }



    render() {
        return (

            <View>
                <SettingItem
                    onPress={this._pressItem.bind(this,0)}
                    source={require('../../imgs/ic_tab_strip_icon_profile.png')}
                    text="测试swiper"
                />
                <SettingItem
                    source={require('../../imgs/ic_tab_strip_icon_profile.png')}
                    text="设置2"
                />
                <SettingItem
                    source={require('../../imgs/ic_tab_strip_icon_profile.png')}
                    text="设置3"
                />
                <SettingItem
                    source={require('../../imgs/ic_tab_strip_icon_profile.png')}
                    text="设置4"
                />
                <TouchableHighlight  underlayColor='#00000000'  onPress={this._loginOut.bind(this)}>
                    <View

                        style={{
                            backgroundColor: '#fff',
                            marginLeft: 30,
                            marginRight: 30,
                            marginTop: 40,
                            flexDirection: 'row',
                            justifyContent: 'center',
                            alignItems: 'center',
                            paddingTop:8,
                            paddingBottom:8,
                        }}>
                        <Text >退出</Text>
                    </View>
                </TouchableHighlight>



            </View>
        );


    };



    //登出，清除本地用户缓存信息，跳转到登陆页面
    _loginOut(){
        base.Store.delete(USER_INFO)
            .then(()=>{
                this.props.navigation.navigate('Login');
            })
        // this.props.navigation.navigate('Login');
        // alert('_loginOut')
    }
}

class SettingItem extends BaseComponent {
    render() {
        return (
        <TouchableOpacity onPress={this.props.onPress}>

            <View style={{
                backgroundColor: '#fff',
                padding: 10,
                flexDirection: 'row',
                alignItems: 'center',
                marginTop: 1
            }}>

                <Image source={this.props.source} style={{width: 20, height: 20, marginRight: 10}}/>
                <Text>{this.props.text}</Text>
            </View>

        </TouchableOpacity>

        )
    }
}